import { RouteRecordRaw, createRouter, createWebHashHistory } from "vue-router"

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "Home",
    component: () => import("@/views/Home/index.vue"),
    meta: {
      title: "首页"
    }
  }
]

const files: Record<string, { default: RouteRecordRaw[] }> = import.meta.glob(
  "@/router/modules/*.ts",
  { eager: true }
)
for (const key in files) {
  const module = files[key].default
  if (module instanceof Array) {
    routes.push(...module)
    continue
  }
  routes.push(module)
}

const router = createRouter({
  routes,
  history: createWebHashHistory()
})

export default router
